package com.opennetexam.manager.sqlprovider;

import org.apache.log4j.Logger;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 奶茶
 * Created on 2017/11/9.
 */
public class ExamineeLoginLogProvider {

    private static Logger logger = Logger.getLogger(ExamineeLoginLogProvider.class);

    /**
     * 条件查询学生登陆日志
     * @param parameter
     * @return
     */
    public String findExamineeLoginLogBySomeWhere(Map<String,Object> parameter){
        StringBuilder stringBuffer = new StringBuilder("SELECT * FROM ExamineeLoginLog WHERE 1 = 1");
        if(parameter.get("examCardNo") != null && !("").equals(parameter.get("examCardNo"))){
            stringBuffer.append(" AND LoginCode LIKE \'%").append(parameter.get("examCardNo")).append("%\'");
        }
        if(parameter.get("loginIp") != null && !("").equals(parameter.get("loginIp"))){
            stringBuffer.append(" AND LoginIPAddress LIKE \'%").append(parameter.get("loginIp")).append("%\'");
        }
        if(parameter.get("loginStatus") != null && !("").equals(parameter.get("loginStatus"))){
            stringBuffer.append(" AND loginStatus LIKE \'%").append(parameter.get("loginStatus")).append("%\'");
        }
        if(parameter.get("beginTime") != null && !("").equals(parameter.get("beginTime"))){
            stringBuffer.append(" AND LoginTime >= \'").append(parameter.get("beginTime")).append("\'");
        }
        if(parameter.get("endTime") != null && !("").equals(parameter.get("endTime"))){
            stringBuffer.append(" AND LoginTime <= \'").append(parameter.get("endTime")).append("\'");
        }
        if(parameter.get("sessionId") != null && !("").equals(parameter.get("sessionId"))){
            stringBuffer.append(" AND SessionID LIKE \'%").append(parameter.get("sessionId")).append("%\'");
        }

        logger.info(stringBuffer.toString());
        return stringBuffer.toString();
    }

    public static void main(String[] args){
        Map<String,Object> map = new HashMap<>();
        map.put("examCardNo","123");
        map.put("loginIp","123");
        map.put("loginStatus","123");
        map.put("beginTime","123");
        map.put("endTime","321");
        map.put("sessionId","123");

    }
}
